#include "PauseState.h"
#include "InputHangdler.h"
#include "TextureManager.h"
#include "Game.h"
#include <iostream>

const std::string PauseState::m_pauseID = "PAUSE";

PauseState::PauseState()
{
	// do nothing
}

PauseState::~PauseState()
{
	// do nothing
}

void PauseState::update()
{
	for (int i = 0; i < 2; i++)
	{
		m_pauseObject[i]->update();
	}
}

void PauseState::render()
{
	for (int i = 0; i < 2; i++)
	{
		m_pauseObject[i]->draw();
	}
}

bool PauseState::init()
{
	if (!TheTextureManager::Instance()->load("resume.png", "resume", TheGame::Instance()->getRenderer()))
	{
		return false;
	}
	if (!TheTextureManager::Instance()->load("menu.png", "menu", TheGame::Instance()->getRenderer()))
	{
		return false;
	}
	// 2 button resume and menu(init game).
	m_sprite_pause_state.loadFile("button.txt");

	MenuButton* buttonResume = new MenuButton(m_resume,m_sprite_pause_state, 0, TheGame::Instance()->getRenderer());
	MenuButton* buttonMenu = new MenuButton(m_menu, m_sprite_pause_state, 0, TheGame::Instance()->getRenderer());

	/*buttonResume->load(10, 10, 50, 50, 25, "resume");
	buttonMenu->load(10, 70, 50, 50, 25, "menu");*/

	m_pauseObject[0] = buttonResume;
	m_pauseObject[1] = buttonMenu;

	std::cout << "Pause state" << endl;

	return true;
}

bool PauseState::exit()
{
	for (int i = 0; i < 2; i++)
	{
		m_pauseObject[i]->clean();
	}

	TheTextureManager::Instance()->clearFromTextureMap("resume");
	TheTextureManager::Instance()->clearFromTextureMap("menu");

	std::cout << "exiting pause state." << endl;

	return true;
}

void PauseState::m_resume()
{
	
	// nothing for now
	TheGame::Instance()->getStateMachine()->popState();
	//TheGame::Instance()->update();
	//TheGame::Instance()->getStateMachine()->changeState(new PlayState());
}

void PauseState::m_menu()
{
	// nothing for now
	TheGame::Instance()->getStateMachine()->changeState(new MenuState());
}

std::string PauseState::getStateID() const
{
	return m_pauseID;
}